home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.4)
-
- import Image
- import ImageColor
-
- try:
- import warnings
- except ImportError:
- warnings = None
-
-
- class ImageDraw:
-
- def __init__(self, im, mode = None):
- im.load()
- if im.readonly:
- im._copy()
-
- blend = 0
- if mode is None:
- mode = im.mode
-
- if mode != im.mode:
- if mode == 'RGBA' and im.mode == 'RGB':
- blend = 1
- else:
- raise ValueError('mode mismatch')
-
- if mode == 'P':
- self.palette = im.palette
- else:
- self.palette = None
- self.im = im.im
- self.draw = Image.core.draw(self.im, blend)
- self.mode = mode
- if mode in ('I', 'F'):
- self.ink = self.draw.draw_ink(1, mode)
- else:
- self.ink = self.draw.draw_ink(-1, mode)
- if mode in ('1', 'P', 'I', 'F'):
- self.fontmode = '1'
- else:
- self.fontmode = 'L'
- self.fill = 0
- self.font = None
-
-
- def setink(self, ink):
- if warnings:
- warnings.warn("'setink' is deprecated; use keyword arguments instead", DeprecationWarning)
-
- if Image.isStringType(ink):
- ink = ImageColor.getcolor(ink, self.mode)
-
- if self.palette and not Image.isNumberType(ink):
- ink = self.palette.getcolor(ink)
-
- self.ink = self.draw.draw_ink(ink, self.mode)
-
-
- def setfill(self, onoff):
- if warnings:
- warnings.warn("'setfill' is deprecated; use keyword arguments instead", DeprecationWarning)
-
- self.fill = onoff
-
-
- def setfont(self, font):
- self.font = font
-
-
- def getfont(self):
- if not self.font:
- import ImageFont
- self.font = ImageFont.load_default()
-
- return self.font
-
-
- def _getink(self, ink, fill = None):
- if ink is None and fill is None:
- if self.fill:
- fill = self.ink
- else:
- ink = self.ink
- elif ink is not None:
- if Image.isStringType(ink):
- ink = ImageColor.getcolor(ink, self.mode)
-
- if self.palette and not Image.isNumberType(ink):
- ink = self.palette.getcolor(ink)
-
- ink = self.draw.draw_ink(ink, self.mode)
-
- if fill is not None:
- if Image.isStringType(fill):
- fill = ImageColor.getcolor(fill, self.mode)
-
- if self.palette and not Image.isNumberType(fill):
- fill = self.palette.getcolor(fill)
-
- fill = self.draw.draw_ink(fill, self.mode)
-
- return (ink, fill)
-
-
- def arc(self, xy, start, end, fill = None):
- (ink, fill) = self._getink(fill)
- if ink is not None:
- self.draw.draw_arc(xy, start, end, ink)
-
-
-
- def bitmap(self, xy, bitmap, fill = None):
- bitmap.load()
- (ink, fill) = self._getink(fill)
- if ink is None:
- ink = fill
-
- if ink is not None:
- self.draw.draw_bitmap(xy, bitmap.im, ink)
-
-
-
- def chord(self, xy, start, end, fill = None, outline = None):
- (ink, fill) = self._getink(outline, fill)
- if fill is not None:
- self.draw.draw_chord(xy, start, end, fill, 1)
-
- if ink is not None:
- self.draw.draw_chord(xy, start, end, ink, 0)
-
-
-
- def ellipse(self, xy, fill = None, outline = None):
- (ink, fill) = self._getink(outline, fill)
- if fill is not None:
- self.draw.draw_ellipse(xy, fill, 1)
-
- if ink is not None:
- self.draw.draw_ellipse(xy, ink, 0)
-
-
-
- def line(self, xy, fill = None, width = 0):
- (ink, fill) = self._getink(fill)
- if ink is not None:
- self.draw.draw_lines(xy, ink, width)
-
-
-
- def shape(self, shape, fill = None, outline = None):
- shape.close()
- (ink, fill) = self._getink(outline, fill)
- if fill is not None:
- self.draw.draw_outline(shape, fill, 1)
-
- if ink is not None:
- self.draw.draw_outline(shape, ink, 0)
-
-
-
- def pieslice(self, xy, start, end, fill = None, outline = None):
- (ink, fill) = self._getink(outline, fill)
- if fill is not None:
- self.draw.draw_pieslice(xy, start, end, fill, 1)
-
- if ink is not None:
- self.draw.draw_pieslice(xy, start, end, ink, 0)
-
-
-
- def point(self, xy, fill = None):
- (ink, fill) = self._getink(fill)
- if ink is not None:
- self.draw.draw_points(xy, ink)
-
-
-
- def polygon(self, xy, fill = None, outline = None):
- (ink, fill) = self._getink(outline, fill)
- if fill is not None:
- self.draw.draw_polygon(xy, fill, 1)
-
- if ink is not None:
- self.draw.draw_polygon(xy, ink, 0)
-
-
-
- def rectangle(self, xy, fill = None, outline = None):
- (ink, fill) = self._getink(outline, fill)
- if fill is not None:
- self.draw.draw_rectangle(xy, fill, 1)
-
- if ink is not None:
- self.draw.draw_rectangle(xy, ink, 0)
-
-
-
- def text(self, xy, text, fill = None, font = None, anchor = None):
- (ink, fill) = self._getink(fill)
- if font is None:
- font = self.getfont()
-
- if ink is None:
- ink = fill
-
- if ink is not None:
-
- try:
- mask = font.getmask(text, self.fontmode)
- except TypeError:
- mask = font.getmask(text)
-
- self.draw.draw_bitmap(xy, mask, ink)
-
-
-
- def textsize(self, text, font = None):
- if font is None:
- font = self.getfont()
-
- return font.getsize(text)
-
-
-
- def Draw(im, mode = None):
-
- try:
- return im.getdraw(mode)
- except AttributeError:
- return ImageDraw(im, mode)
-
-
-
- try:
- Outline = Image.core.outline
- except:
- Outline = None
-
-